package com.ruoyi.system.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.constant.Constants;
import lombok.*;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 附件管理对象 sys_attachment
 *
 * @author shuyan
 * @date 2021-01-13
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sys_attachment")
public class SysAttachment implements Serializable {

    private static final long serialVersionUID = 1L;


    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 业务场景
     */
    private String businessType;

    /**
     * 文件上传名称
     */
    private String fileName;

    /**
     * 文件存储名称
     */
    private String realName;

    /**
     * 文件路径
     */
    @Setter(AccessLevel.NONE)
    private String filePath;

    /**
     * 文件扩展名
     */
    private String fileExt;

    /**
     * 描述
     */
    private String remark;

    /**
     * 上传时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @OrderBy
    private Date saveTime;

    /**
     * 上传人用户名
     */
    private String saveUserName;

    /**
     * 上传人昵称
     */
    private String saveNickName;

    @TableField(exist = false)
    private String downloadPath;

    @TableField(exist = false)
    private Map<String, Object> params = new HashMap<>();

    /**
     * 覆盖文件路径setter,设置下载路径
     */
    public void setFilePath(String filePath) {
        this.filePath = filePath;
        if (StringUtils.isNotBlank(filePath)) {
            this.downloadPath = Constants.RESOURCE_PREFIX + filePath;
        }
    }
}
